<template>
  <view :style="themeColor">
    <view class="page">
      <!---flex布局flex布局开始-->
      <view class="flex flex-wrap align-center justify-center benben-flex-layout login_flex_0">
        <image class='login_fd0_0' mode="aspectFit" :src='STATIC_URL+"22.png"'></image>
      </view>

      <!---flex布局flex布局结束-->
      <!---flex布局flex布局开始-->
      <view class="flex benben-flex-layout flex-wrap align-center login_flex_1">
        <view>
          <benben-flex-tabs class-name='login_benbenTabsfd1_0' v-model="tabls" ref="benben_tabsfd1_0"
            select-mark="benben_tabsfd1_0" key="benben_tabsfd1_0" :open-title-type='false' :open-sticky='true' :top='0'
            :is-show-content='false' :scrollspy='false' :tabs-info.sync="tabsInfofd1_0">

            <scroll-view @scroll="tabsInfofd1_0.scrollX = $event.detail.scrollLeft" id="benben_tabsfd1_0"
              class="benben-tabs" style="width:750rpx" :scroll-x="true" :scroll-left.sync="tabsInfofd1_0.moveX"
              scroll-with-animation="all .3s ease">
              <view class="benben-tabs-content" id="benben_tabsfd1_0-content">
                <view id="benben_tabsfd1_0-title" class="benben-tabs-title flex align-center flex ">
                  <view
                    :class="{ 'checkTitlefd1_0': tabls == 'account', 'flex flex-wrap align-center login_titlefd1_0_c3': true }"
                    @tap="tabls = 'account'" :id="`benben_tabsfd1_0-title-item-${'account'}`">

                    <text>{{$t('手机号登录')}}</text>

                  </view>
                  <view
                    :class="{ 'checkTitlefd1_0': tabls == 'email', 'flex flex-wrap align-center login_titlefd1_0_c4': true }"
                    @tap="tabls = 'email'" :id="`benben_tabsfd1_0-title-item-${'email'}`">

                    <text>{{$t('邮箱号登录')}}</text>

                  </view>
                </view>
                <view :style="{ left: tabsInfofd1_0.lineleft, maxWidth: tabsInfofd1_0.lineWidth ,}"
                  id="benben_tabsfd1_0-line" class="benben-tabs-line flex benben-flex-tabs-line login_linefd1_0"></view>
              </view>
            </scroll-view>

          </benben-flex-tabs>

        </view>
      </view>

      <!---flex布局flex布局结束-->
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout login_flex_2">
        <view class='flex flex-wrap align-center login_fd2_0' v-if=" tabls=='account'">
          <view class='flex flex-wrap align-center codeLogin_fd1_3_c1' @click.stop="pickerDiy1704874099380=true">
            <text class='codeLogin_fd1_3_c1_c0'>+{{area_code}}</text>
            <image class='codeLogin_fd1_3_c1_c1' mode="aspectFit" :src='STATIC_URL+"1111.png"'></image>
          </view>
          <input class='flex-sub login_fd2_0_c1' type="number" :placeholder="$t('请输入手机号')" confirm-type="done"
            :maxlength="20" placeholder-style="color:rgba(102, 102, 102, 1);font-size:28rpx"
            v-model="dataObj.actount" />
        </view>
        <view class='flex flex-wrap align-center login_fd2_0' v-if=" tabls=='email'">
          <image class='login_fd2_0_c0' mode="aspectFit" :src='STATIC_URL+"27.png"'></image>
          <input class='flex-sub login_fd2_0_c1' type="text" :placeholder="$t('请输入邮箱号')" confirm-type="done"
            :maxlength="-1" placeholder-style="color:rgba(102, 102, 102, 1);font-size:28rpx" v-model="dataObj.mail" />
        </view>
        <view class='flex flex-wrap align-center login_fd2_0'>
          <image class='login_fd2_0_c0' mode="aspectFit" :src='STATIC_URL+"24.png"'></image>
          <benben-flex-password-diy v-model="dataObj.paswarld" class-name="flex flex align-center login_fd2_2_c1"
            :placeholder="$t('请输入密码(6~12位字母+数字)')" :maxlength="12" :default-type='true'
            placeholder-style="color:#999;font-size:28rpx">
            <template #show>
              <text class='fu-iconfont2  login_fd2_2_c1_icon1' data-type="show">&#xE837;</text>
            </template>
            <template #hide>
              <text class='fu-iconfont2  login_fd2_2_c1_icon2' data-type="hide">&#xEBCC;</text>
            </template>
          </benben-flex-password-diy>
        </view>
        <view class='flex flex-wrap align-center justify-end login_fd2_3' @tap.stop="handleJumpDiy"
          data-type="navigateTo" :data-url="`/pages/dlzc/codeLogin/codeLogin`">
          <text class='login_fd2_3_c0'>{{$t('验证码登录')}}</text>
        </view>
        <view class='flex flex-wrap align-center justify-center login_fd2_4'>
          <button class='login_fd2_4_c0' @tap.stop="validatioLoginFunc()">{{$t('登录')}}</button>
        </view>
        <view class='flex flex-wrap align-center justify-center login_fd2_4'>
          <text class='login_fd2_5_c0' @tap.stop="handleJumpDiy" data-type="navigateTo"
            :data-url="`/pages/dlzc/registerLogin/registerLogin`">{{$t('注册账号')}}</text>
          <text class='login_fd2_5_c1'>|</text>
          <text class='login_fd2_5_c0' @tap.stop="handleJumpDiy" data-type="navigateTo"
            :data-url="`/pages/dlzc/forgetPasw/forgetPasw`">{{$t('忘记密码')}}</text>
        </view>
        <view class="text-sm text-weight-600 margin-top-sm  gohome" @tap.stop="handleJumpDiy" data-type="switchTab"
          :data-url="`/pages/tabBar/homePage/homePage`">去主页</view>
      </view>

      <!---flex布局flex布局结束-->
      <view class="flex flex-direction flex-wrap align-stretch benben-position-layout flex login_flex_3">
        <view class='flex flex-direction flex-wrap align-stretch flex-sub'>
          <view class='flex flex-wrap align-center justify-center' @click.stop="wxLogin">

            <view class='flex  login_fd3_0_c0_c0'></view>

            <text class='login_fd3_0_c0_c1'>{{$t('快捷登录')}}</text>

            <view class='flex  login_fd3_0_c0_c0'></view>

          </view>
          <view class='flex flex-wrap align-center justify-center login_fd3_0_c1' @click.stop="wxLogin">
            <image class='login_fd3_0_c1_c0' mode="aspectFit" :src='STATIC_URL+"26.png"'></image>
          </view>
          <view class='flex flex-wrap align-center justify-center login_fd3_0_c2'>
            <benben-flex-switch-new class-name='flex flex login_fd3_0_c2_c0' v-model="dataObj.is_tick" :disabled='false'
              :auto='true'>
              <template v-slot:checked>

                <view class='flex flex position-relative align-center'>
                  <image class='login_checkfd3_0_c2_c0_c0_c0' mode="aspectFit" :src='STATIC_URL+"2.png"'></image>
                </view>

              </template>
              <template v-slot:unchecked>

                <view class='flex flex position-relative justify-end align-center'>
                  <image class='login_noCheckfd3_0_c2_c0_c1_c0' mode="aspectFit" :src='STATIC_URL+"96.png"'></image>
                </view>

              </template>
            </benben-flex-switch-new>
            <text class='login_fd3_0_c2_c1'>{{$t('勾选即默认同意')}}</text>
            <text class='login_fd3_0_c2_c2' @tap.stop="handleJumpDiy" data-type="navigateTo"
              :data-url="`/pages/dlzc/agreements/agreements`">{{$t('《用户注册协议》')}}</text>
            <text class='login_fd3_0_c2_c1'>{{$t('与')}}</text>
            <text class='login_fd3_0_c2_c2' @tap.stop="handleJumpDiy" data-type="navigateTo"
              :data-url="`/pages/dlzc/privacyPolicy/privacyPolicy`">{{$t('《隐私政策》')}}</text>
          </view>
        </view>

      </view>
      <view :style="{height: '253rpx'}"></view>
      <benben-picker ref="benbenWritePickerCodepicker2" :visible.sync="pickerDiy1704874099380" :value.sync='area_code'
        :options='areaList' mode='selector' :mask-show='true' :timeout='true' :picker-height='88' default-type='quhao'
        :default-props='{"label":"guojia","value":"quhao"}'>
        <template #picker-header>
          <view class='flex flex-wrap align-center justify-between myProfile_picker2_0'>
            <text class='myProfile_picker2_0_c0' @tap="$refs.benbenWritePickerCodepicker2.cancel()">取消</text>
            <text>选择区号</text>
            <text class='myProfile_picker2_0_c2' @tap="$refs.benbenWritePickerCodepicker2.pickerConfirm()">确认</text>
          </view>
        </template>
      </benben-picker>

    </view>

  </view>
</template>
<script>
  import {
    validate
  } from '@/common/utils/validate.js'
  export default {
    components: {},


    data() {
      return {
        "tabsInfofd1_0": {
          lineleft: '',
          lineWidth: '',
          moveX: 0,
          scrollX: 0,
          PageScrollX: 0
        },
        "tabls": "account",
        "dataObj": {
          "actount": "",
          "mail": "",
          "paswarld": "",
          "is_tick": false
        },
        "data": {
          "userinfo": {
            "user_token": "",
            "id": "",
            "avatar": "",
            "real_name": "",
            "nickname": "",
            "email": "",
            "gender": "",
            "mobile": "",
            "birthday": "",
            "client_id": "",
            "phone": ""
          }
        },
        "code": "",
        areaList: [],
        area_code: '',
        pickerDiy1704874099380: false,
      };
    },
    computed: {
      themeColor() {
        return this.$store.getters.themeColor
      },

    },
    watch: {},
    onLoad(options) {
      this.$api.post(global.apiUrls.post65ea6e2f5dcb9).then(res => {
        if (res.data.code == 1) {
          this.areaList = res.data.data
          this.area_code = this.areaList[0].quhao
        }
      })
    },
    onUnload() {

    },
    onReady() {

    },
    onShow() {
      this.tabls = "account"
    },
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {

    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      // 三方登录
      wxLogin() {
        let _this = this;
        if (_this.dataObj.is_tick === false) {
          _this.$message.info(global.i18n.t('请勾选用户协议'));
          return false;
        }
        // #ifdef APP-PLUS
        // 如果是app环境打开微信
        if (
          plus.runtime.isApplicationExist({
            pname: "com.tencent.mm",
            action: "weixin://",
          })
        ) {
          uni.getProvider({
            service: "oauth",
            success: function(res) {
              console.log(res);
              // 如果支持微信等，就执行 wx_login_fn 方法
              if (~res.provider.indexOf("weixin")) {
                _this.wx_login_fn();
              }
            },
            fail: function(err) {
              // api错误是打印错误
              console.log(err);
            },
          });
        } else {
          // 调起失败时提醒用户
          this.$message.info(this.i18n["请安装微信后再使用此功能"]);
        }
        // #endif
      },
      /**
       * @function 微信授权登录
       */
      wx_login_fn() {
        let _this = this;
        /**
         * @desc uniapp的登陆api
         * @param {String} provider - 登录服务提供商
         * @param {login~success} loginRes - 接口调用成功时的回调函数
         */
        uni.login({
          provider: "weixin",
          /**
           * @callback login~success
           * @param {Object} loginRes - api返回来的信息
           */
          success: function(loginRes) {
            console.log('loginRes', loginRes)
            /**
             * @desc 获取用户信息
             * @param {String} provider - 登录服务提供商
             * @param {Funtion} success - 接口调用成功时的回调函数
             */
            uni.getUserInfo({
              provider: "weixin",
              /**
               * @callback success
               * @param {Object} infoRes - api返回来的信息
               */
              success: function(infoRes) {
                // 显示加载状态
                uni.showLoading({
                  title: '加载中...',
                });
                /**
                 * @let {String} nickName - 结构出来的变量昵称
                 * @let {String} avatarUrl - 解构出来的头像链接
                 * @let {String} gender - 结构出来的性别
                 */
                let {
                  nickName,
                  avatarUrl,
                  gender
                } = infoRes.userInfo;
                // #ifdef APP-PLUS
                // let clientId =  plus.push.getClientInfo().clientid;
                // console.log("clientId", clientId);
                //  @const {Number} appSystem - 判断设备类型 1：ios；2：安卓；
                let appSystem = uni.getSystemInfoSync().platform == "ios" ? 1 : 2;
                // #endif
                console.log(JSON.stringify(infoRes.userInfo), "app微信登录");
                /**
                 * @description 第三方登录请求接口
                 */
                _this.$api
                  .post(global.apiUrls.postUserSocialLogin, {
                    third_type: "wx_app",
                    extend_info: JSON.stringify(infoRes.userInfo),
                    wx_unionid: infoRes.userInfo.unionId,
                    qq_unionid: "",
                    wb_unionid: "",
                    // clientId: clientId || "",
                    appSystem: appSystem || "",
                    nickname: nickName,
                    avatar: avatarUrl,
                    gender: gender,
                  })
                  .then((res) => {
                    console.log('ppppppppp', res)
                    // 保存用户信息
                    global.tempUserLoginInfo = infoRes.userInfo;
                    // 关闭加载效果
                    uni.hideLoading();
                    if (res.data.code == 1) {
                      _this.$message.info(res.data.msg);
                      /**
                       * @description 向Vux发送用户信息保存
                       * @param {String} updateUserInfo - 调用的方法名称
                       * @param {Object} res.data.data.userinfo - 用户信息
                       */
                      console.log('ppppppppp', res.data.data.userinfo)
                      _this.$store.commit('saveToken', res.data.data.userinfo.user_token)
                      _this.$store.commit("updateUserInfo", res.data.data);
                      console.log('res.data.data.userinfo', res.data.data.userinfo)
                      setTimeout(ressss => {
                        _this.toHomeDiy();
                      }, 500)
                    } else if (res.data.code == -999) {
                      let bandInfo = res.data.data.result
                      // 点击手机号账号登录按钮
                      uni.navigateTo({
                        url: `/pages/dlzc/bindPhone/bindPhone?bandInfo=${JSON.stringify(bandInfo)}`
                      })
                    } else if (res.code == -1) {
                      _this.$message.info(res.data.msg);
                      return;
                    } else {
                      _this.$message.info(res.data.msg);
                    }
                  })
                  .catch((err) => {
                    uni.hideLoading();
                    console.log('ooooo', err);
                  });
              },

            });
          },
          error: function(err) {
            uni.hideLoading();
            console.log(err, 'errrrrrrrrrrr');
          },
          complete: function(complete) {
            // uni.hideLoading();
            console.log(complete, 'complete');
          },
        });
      },
      // enddd
      //效验登录
      async validatioLoginFunc() {
        if (this.tabls == 'account') {
          if (!validate(this.dataObj.actount, 'require')) {
            this.$message.info(global.i18n.t('手机号不能为空'));
            return false;
          }
          // if (!validate(this.dataObj.actount, 'phone')) {
          //   this.$message.info(global.i18n.t('请输入正确的手机号'));
          //   return false;
          // }
        } else if (this.tabls == 'email') {
          if (!validate(this.dataObj.mail, 'require')) {
            this.$message.info(global.i18n.t('邮箱号不能为空'));
            return false;
          }
          if (!validate(this.dataObj.mail, 'email')) {
            this.$message.info(global.i18n.t('请输入正确的邮箱号'));
            return false;
          }
        }
        if (!validate(this.dataObj.paswarld, 'require')) {
          this.$message.info(global.i18n.t('密码不能为空'));
          return false;
        }
        if (!validate(this.dataObj.paswarld, 'password')) {
          this.$message.info(global.i18n.t('请输入密码(6~12位字母+数字)'));
          return false;
        }
        if (this.dataObj.is_tick === false) {
          this.$message.info(global.i18n.t('请勾选用户协议'));
          return false;
        }
        if (this.tabls == 'account') {
          this.dataObj.mail = ''
        } else {
          this.dataObj.actount = ''
        }
        //请求方法
        //数据验证

        let datadata = await this.$api.post(global.apiUrls.post5c78dbfd977cf, {
          account: this.tabls == 'account' ? this.dataObj.actount : this.dataObj.mail,
          account_type: this.tabls == 'account' ? 'mobile' : 'email',
          password: this.dataObj.paswarld,
          quhao: this.area_code
        });

        if (datadata.data.code != 1) {
          this.$message.info(datadata.data.msg);
          return
        }
        let infodata = datadata.data;
        this.data = infodata.data

        this.$store.commit('saveToken', this.data.userinfo.user_token)
        this.$store.commit('updateUserInfo', this.data.userinfo)
        this.toHomeDiy();
      }
    }
  };
</script>
<style lang="scss" scoped>
  .gohome {
    text-align: center;
    color: #912F22;
  }

  .codeLogin_fd1_3_c1_c1 {
    width: 14rpx;
    height: 8rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
  }

  .codeLogin_fd1_3_c1_c0 {
    color: #333333;
    font-size: 28rpx;
    font-weight: 400;
    line-height: 34rpx;
    margin: 0rpx 10rpx 0rpx 0rpx;
  }

  .codeLogin_fd1_3_c1 {
    margin: 0rpx 24rpx 0rpx 0rpx;
  }

  .myProfile_picker2_0_c2 {
    color: rgba(100, 80, 235, 1);
  }

  .myProfile_picker2_0_c0 {
    color: var(--benbenFontColor2);
  }

  .myProfile_picker2_0 {
    border-bottom: 1px solid #eee;
    background: #fff;
    padding: 0rpx 32rpx 0rpx 32rpx;
    line-height: 88rpx;
    border-radius: 25rpx 25rpx 0rpx 0rpx;
    background-size: 100% auto !important;
  }



  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: url(image-path('21.png')) no-repeat, #F7F3ED;
    background-size: 100% auto;
  }

  .login_flex_0 {
    padding: 105rpx 0rpx 0rpx 0rpx;
  }

  .login_fd0_0 {
    width: 136rpx;
    height: 141rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
  }

  .login_flex_1 {
    margin: 87rpx 0rpx 0rpx 0rpx;
  }

  .login_titlefd1_0_c4 {
    margin: 0rpx 0rpx 0rpx 48rpx;
  }

  .login_titlefd1_0_c3 {
    margin: 0rpx 0rpx 0rpx 64rpx;
  }

  .login_linefd1_0 {
    background: rgba(145, 47, 34, 1);
    width: 45rpx;
    height: 12rpx;
    top: 80rpx;
    background-size: 100% auto !important;
    border-radius: 44rpx;
  }

  .checkTitlefd1_0 {
    font-weight: 700 !important;
    font-size: 28rpx !important;
    color: #333 !important;
  }

  ::v-deep .login_benbenTabsfd1_0 {
    width: 750rpx;
    height: 90rpx;
    white-space: nowrap;
    text-align: center;
    font-size: 28rpx;
    font-weight: 500;
    color: #666666;
  }

  .login_flex_2 {
    padding: 0rpx 64rpx 0rpx 64rpx;
    margin: 55rpx 0rpx 0rpx 0rpx;
  }

  .login_fd2_5_c1 {
    color: #666666;
    font-size: 28rpx;
    font-weight: 400;
    line-height: 34rpx;
    margin: 0rpx 20rpx 0rpx 20rpx;
  }

  .login_fd2_5_c0 {
    color: #666666;
    font-size: 28rpx;
    font-weight: 400;
    line-height: 34rpx;
  }

  .login_fd2_4_c0 {
    background: rgba(145, 47, 34, 1);
    border-radius: 44rpx;
    width: 616rpx;
    line-height: 88rpx;
    font-size: 32rpx;
    color: #fff;
  }

  .login_fd2_4 {
    margin: 40rpx 0rpx 0rpx 0rpx;
  }

  .login_fd2_3_c0 {
    color: #987040;
    font-size: 24rpx;
    font-weight: 400;
    line-height: 32rpx;
  }

  .login_fd2_3 {
    margin: 32rpx 0rpx 0rpx 0rpx;
  }

  .login_fd2_2_c1_icon2 {
    width: 88rpx;
    line-height: 88rpx;
    text-align: center;
    font-size: 40rpx;
  }

  .login_fd2_2_c1_icon1 {
    text-align: center;
    font-size: 40rpx;
  }

  ::v-deep .login_fd2_2_c1 {
    width: 543rpx;
    font-size: 28rpx;
    height: 32rpx;
    color: #333;
  }

  .login_fd2_0_c1 {
    font-size: 28rpx;
    color: #333;
  }

  .login_fd2_0_c0 {
    width: 36rpx;
    height: 36rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    margin: 0rpx 32rpx 0rpx 0rpx;
  }

  .login_fd2_0 {
    border-bottom: 1px solid rgba(232, 229, 216, 1);
    padding: 32rpx 0rpx 32rpx 0rpx;
  }

  .login_flex_3 {
    width: 750rpx;
    height: 253rpx;
    overflow: hidden;
    z-index: 10;
    bottom: calc(42rpx + var(--window-bottom));
  }

  .login_fd3_0_c2_c2 {
    color: #333333;
    font-size: 22rpx;
    font-weight: 800;
    line-height: 32rpx;
  }

  .login_fd3_0_c2_c1 {
    color: rgba(153, 153, 153, 1);
    font-size: 22rpx;
    font-weight: 800;
    line-height: 32rpx;
  }

  .login_noCheckfd3_0_c2_c0_c1_c0 {
    border-radius: 24rpx 24rpx 24rpx 24rpx;
    width: 32rpx;
    height: 32rpx;
  }

  .login_checkfd3_0_c2_c0_c0_c0 {
    width: 32rpx;
    height: 32rpx;
    border-radius: 24rpx 24rpx 24rpx 24rpx;
  }

  ::v-deep .login_fd3_0_c2_c0 {
    margin: 0rpx 16rpx 0rpx 0rpx;
  }

  .login_fd3_0_c2 {
    margin: 45rpx 0rpx 0rpx 0rpx;
  }

  .login_fd3_0_c1_c0 {
    width: 80rpx;
    height: 80rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    margin: 0rpx 0rpx 0rpx 0rpx;
  }

  .login_fd3_0_c1 {
    margin: 40rpx 0rpx 0rpx 0rpx;
  }

  .login_fd3_0_c0_c1 {
    color: #999999;
    font-size: 26rpx;
    font-weight: 400;
    line-height: 32rpx;
    margin: 0rpx 10rpx 0rpx 10rpx;
  }

  .login_fd3_0_c0_c0 {
    background: #EEEEEE;
    width: 156rpx;
    height: 1rpx;
    margin: 10rpx 0rpx 10rpx 0rpx;
    transform: scaleY(0.5);
    border-radius: 1rpx 1rpx 1rpx 1rpx;
  }
</style>
